package speed2010.matcher.gui;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;

import speed2010.matcher.gui.FOntologyMatcherGUI;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FRun extends JDialog {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2087596334125695703L;
	
	private JCheckBox chkSemanticMatching;
	private JButton btnCancel;
	private JButton btnOk;
	private JCheckBox chkSimilarityMeasure;
	private JCheckBox chkFinalAlignment;
	
	public static boolean SEMANTIC_MATCHING;
	public static boolean FINAL_ALIGN;
	public static boolean SIMILARITY;

	public FRun()
	{
		super(FOntologyMatcherGUI.INSTANCE, "", ModalityType.APPLICATION_MODAL);
		initialize();
		SEMANTIC_MATCHING = false;
		SIMILARITY = false;
		FINAL_ALIGN = false;
	}
	
	private void initialize() {
		
		this.setSize(470, 167);
		this.setTitle("Run");
		this.setLayout(null);
		this.setLocationRelativeTo(FOntologyMatcherGUI.INSTANCE);
		this.setResizable(false);
		getContentPane().add(getChkSemanticMatching());
		getContentPane().add(getChkFinalAlignment());
		getContentPane().add(getChkSimilarityMeasure());
		getContentPane().add(getBtnRun());
		getContentPane().add(getBtnCancel());

	}
		
	private boolean isSomeOptionChecked()
	{
		boolean isSomeOptionChecked = false;
		
		if(chkSemanticMatching.isSelected()
				||
				chkFinalAlignment.isSelected()
				||
				chkSimilarityMeasure.isSelected())
		{
			isSomeOptionChecked = true;
		}
		
		
		return isSomeOptionChecked;
	}
	
	private boolean isOnlySemanticMatchingChecked()
	{
		boolean isOnlySemanticMatchingChecked = false;
		
		if(chkSemanticMatching.isSelected()
				&&
				!chkFinalAlignment.isSelected()
				&&
				!chkSimilarityMeasure.isSelected())
		{
			isOnlySemanticMatchingChecked = true;
		}
		
		
		return isOnlySemanticMatchingChecked;
	}
	
	private JCheckBox getChkSemanticMatching()
	{
		if(chkSemanticMatching == null)
		{
			chkSemanticMatching = new JCheckBox();			
			chkSemanticMatching.setText("Semantic Alignment (Phase 1)");
			chkSemanticMatching.setBounds(12, 27, 184, 22);
			chkSemanticMatching.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					btnOk.setEnabled(isSomeOptionChecked());
				}
			});
		}
		return chkSemanticMatching;
	}
	
	private JCheckBox getChkFinalAlignment() {
		if(chkFinalAlignment == null) {
			chkFinalAlignment = new JCheckBox();
			chkFinalAlignment.setText("Final Alignment (Phases 1 and 2)");
			chkFinalAlignment.setBounds(12, 58, 195, 20);
			chkFinalAlignment.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					btnOk.setEnabled(isSomeOptionChecked());
				}
			});
		}
		return chkFinalAlignment;
	}
	
	private JCheckBox getChkSimilarityMeasure() {
		if(chkSimilarityMeasure == null) {
			chkSimilarityMeasure = new JCheckBox();
			chkSimilarityMeasure.setText("Global Similarity Measure (Phases 1 and 2)");
			chkSimilarityMeasure.setBounds(207, 28, 257, 20);
			chkSimilarityMeasure.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					btnOk.setEnabled(isSomeOptionChecked());
				}
			});
		}
		return chkSimilarityMeasure;
	}
	
	private JButton getBtnRun() {
		if(btnOk == null) {
			btnOk = new JButton();
			btnOk.setText("Run");
			btnOk.setBounds(173, 98, 60, 22);
			btnOk.setEnabled(false);
			btnOk.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					updateData();
					if(isOnlySemanticMatchingChecked())
					{
						FOntologyMatcherGUI.INSTANCE.getMainPanel().executeSemanticMatching();
					}
					else
					{
						FOntologyMatcherGUI.INSTANCE.getMainPanel().calculateSSM();
					}
					setVisible(false);
				}

				private void updateData() {
					if(chkSemanticMatching.isSelected())
					{
						SEMANTIC_MATCHING = true;
					}
					if(chkFinalAlignment.isSelected())
					{
						FINAL_ALIGN = true;
					}
					if(chkSimilarityMeasure.isSelected())
					{
						SIMILARITY = true;
					}
					
				}
			});
		}
		return btnOk;
	}
	
	private JButton getBtnCancel() {
		if(btnCancel == null) {
			btnCancel = new JButton();
			btnCancel.setText("Cancel");
			btnCancel.setBounds(238, 98, 80, 22);
			btnCancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					SEMANTIC_MATCHING = false;
					SIMILARITY = false;
					FINAL_ALIGN = false;
					setVisible(false);
				}
			});
		}
		return btnCancel;
	}
	
	

}
